/*
 * Sii Commons
 *
 * Copyright (c) 2011 Sii Sp. z o.o. All rights reserved.
 */
package com.gdziarmaga.webshop.utils.filtering;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

/**
 * Base filter uses in services.
 * 
 * @author Radosław Ryś
 * @version 1.0
 *
 */
public class BaseFilter implements Serializable {
    
    /**
     * serialVersionUID
     */
    private static final long serialVersionUID = 9168851522632697148L;
    
    /**
     * Array for {@link FilterField}.
     */
    private List<FilterField<?>> filterFields;

    /**
     * Constructor.
     */
    public BaseFilter() {
        this.filterFields = new ArrayList<FilterField<?>>();
    }
    
    /**
     * Constructor.
     */
    public BaseFilter(FilterField<?>[] filerFields) {
        this.filterFields = new ArrayList<FilterField<?>>();
    }

    /**
     * Adds {@link FilterField} to internal list.
     * 
     * @param filerField the {@link FilterField} to add
     * @return the added {@link FilterField}
     */
    public FilterField<?> addFilterField(FilterField<?> filerField) {
        filterFields.add(filerField);
        return filerField;
    }

    /**
     * Adds all {@link FilterField} from filter to internal list. 
     * @param filter the another {@link BaseFilter}
     */
    public void mergeFilters(BaseFilter filter) {
        if(filter != null){
            filterFields.addAll(filter.getFilterFields());
        }
    }
    
    /**
     * Getter for filterFields.
     * 
     * @return the filterFields
     */
    public List<FilterField<?>> getFilterFields() {
        return filterFields;
    }

}
